<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<body class="hold-transition skin-blue sidebar-mini">
<section class="content-header">
    <h1>
        项目剩余量
    </h1>
</section>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <form id="queryForm" action="/material/proToIty/exportExcel">
                        <div class="row">
                            <div class="form-inline">
                                <div class="form-group">
                                    <label>项目编号</label>
                                    <input type="text" name="ityProCode" id="ityProCode"
                                           class="form-control"
                                           placeholder="请输入项目编号">
                                </div>
                                <div class="form-group">
                                    <label>项目名称</label>
                                    <input type="text" name="ityProName" id="ityProName"
                                           class="form-control"
                                           placeholder="请输入项目名称">
                                </div>
                                <div class="form-group">
                                    <label>跟踪号</label>
                                    <input type="text" name="ityTrackCode" id="ityTrackCode"
                                           class="form-control"
                                           placeholder="请输入跟踪号">
                                </div>
                                <div class="form-group">
                                    <label>标记人员</label>
                                    <input type="text" name="pimProposer" id="pimProposer"
                                           class="form-control"
                                           placeholder="请输入标记人员">
                                </div>
                                <div class="form-group">
                                    <label>状态</label>
                                    <select name="pimAppStatus" class="form-control" id="pimAppStatus">
                                        <option th:if="${pimAppStatus}==2" value="2">未执行</option>
                                        <option th:if="${pimAppStatus}==3" value="3">已执行</option>
                                        <option th:if="${pimAppStatus}==4" value="4">驳回</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label>标记日期</label>
                                    <input type="text" class="form-control datepicker" name="startTimeQuery"
                                           id="startTimeQuery"
                                           th:value="${startDate}"
                                           readonly="readonly"/>
                                    <span>至</span>
                                    <input type="text" class="form-control datepicker" name="endTimeQuery"
                                           id="endTimeQuery"
                                           th:value="${endDate}"
                                           readonly="readonly"/>
                                </div>
                                <button type="button" class="btn btn-success" id="btn_search">搜索</button>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="row" id="toolbar">
                    <div class="form-inline">
                        <button type="button" id="btn_exportExcel"
                                shiro:hasPermission="matinv:matprowarexec:view"
                                class="btn btn-primary">
                            导出
                        </button>
                    </div>
                </div>
                <div class="box-body">
                    <table id="bootstrap-table"></table>
                </div>
            </div>
        </div>
    </div>
</section>
<div th:include="include :: footer"></div>
<script th:inline="javascript">

    /** 单条执行 */
    function checkSingle(id) {
        js.modal.confirm("确定执行项目划库存吗？", function (result) {
            js.post({
                url: ctx + "material/proToIty/checkSingle",
                data: {
                    pimId: id
                },
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        js.table.refresh(table);
                    } else {
                        js.modal.warning(result.msg);
                    }
                    js.modal.closeLoading();
                }
            })
        })
    }

    /** 驳回 */
    function updateStatus(id, status) {
        js.modal.confirm("确定驳回项目划库存吗？", function (result) {
            js.post({
                url: ctx + "material/proToIty/updateStatus",
                data: {
                    pimId: id,
                    pimAppStatus: status
                },
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        js.table.refresh(table);
                    } else {
                        js.modal.warning(result.msg);
                    }
                    js.modal.closeLoading();
                }
            })
        })
    }

    /** 单条撤销 */
    function cancelSingle(id) {
        js.modal.confirm("确定撤销项目划库存吗？", function (result) {
            js.post({
                url: ctx + "material/proToIty/cancelSingle",
                data: {
                    pimId: id
                },
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        js.table.refresh(table);
                    } else {
                        js.modal.warning(result.msg);
                    }
                    js.modal.closeLoading();
                }
            })
        })
    }

    $(function () {

        /** 加载列表 */
        table = js.table.init({
            url: ctx + "material/proToIty/markList",
            pageSize: 300,
            queryData: {sourceFlgQuery: 2},
            columns: [
                {title: '物料描述', field: 'matNameDesc'},
                {title: '跟踪号', field: 'ityTrackCode'},
                {title: '项目编号', field: 'ityProCode'},
                {title: '项目名称', field: 'ityProName'},
                {title: '特殊说明', field: 'itySpec'},
                {title: '标记数量', field: 'pimNum'},
                {title: '标记重量', field: 'pimWeight'},
                {
                    title: '状态', field: 'pimAppStatus', width: '80',
                    formatter: function (value, row, index) {
                        if (value === 2) {
                            return '<span class="badge bg-yellow">未执行</span> ';
                        } else if (value === 3) {
                            return '<span class="badge bg-green">已执行</span> ';
                        } else if (value === 4) {
                            return '<span class="badge bg-red">驳回</span> ';
                        }
                    }
                },
                {title: '标记人员', field: 'pimProposer'},
                {title: '标记时间', field: 'pimDate', width: '90'}
            ]
        });

        /** 表格搜索 */
        $("#btn_search").click(function () {
            js.table.search(table);
        });

        /** 批量执行 */
        $("#btn-togetherCheck").click(function () {

            var rows = js.table.selectRows("bootstrap-table");

            // 如果没有选择，显示提示信息
            if (rows.length == 0) {
                js.modal.warning("请至少选择一条明细");
                return false;
            } else {
                var arr = js.table.selectColumns(table, "pimId");
                js.post({
                    url: ctx + "material/proToIty/checkTogether",
                    contentType: "application/json",
                    data: JSON.stringify(arr),
                    success: function (result) {
                        if (result.type === web_status.SUCCESS) {
                            js.modal.success(result.msg);
                            js.table.refresh(table);
                        } else {
                            js.modal.warning(result.msg);
                            js.table.refresh(table);
                        }
                        js.modal.closeLoading();
                    }
                })
            }
        });

        /**
         * 导出Excel
         */
        $("#btn_exportExcel").click(function () {

            // // 判断表单数据是否为空,为空不允许导出
            // var isAllEmpty = true;
            // var t = $('#queryForm').serializeArray();
            // $.each(t, function (i, item) {
            //     if (item['value'] != '' && item['name'] != 'startTimeQuery' && item['name'] != 'endTimeQuery') {
            //         isAllEmpty = false;
            //     }
            // })
            // if (isAllEmpty) {
            //     $("#ityProCode").focus();
            //     js.modal.warning("请填写非日期类导出筛选条件！");
            //     return false;
            // }
            //
            // if ($('#ityProCode').val() == '' && $('#ityProName').val() == ''
            //     && $('#ityTrackCode').val() == '' && $('#pimProposer').val() == '' && $('#pimAppStatus').val() == '3') {
            //     $("#ipmInProjectCode").focus();
            //     js.modal.warning("请填写非日期类导出筛选条件！");
            //     return false;
            // }

            $("#queryForm").submit();
        });

    })

</script>
</body>
</html>